public class DFS {
    DFS childNode;

    String name;



    public DFS(String name) {
    this.name=name;
    }

    public DFS(DFS childNode,String name) {
        this.childNode = childNode;
        this.name=name;
    }


    public void process(){
        if (childNode!=null){
            childNode.process();
        }
        System.out.println(name);
    }


    public static void main(String[] args) {
        DFS dfs5=new DFS("5");

        DFS dfs4=new DFS(dfs5,"4");

        DFS dfs3=new DFS(dfs4,"3");

        DFS dfs2=new DFS(dfs3,"2");

        DFS dfs1=new DFS(dfs2,"1");

        dfs1.process();

    }




}
